package com.example.bzh.gamecat.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.bzh.gamecat.bean.HotTag;
import com.example.bzh.gamecat.bean.UserBean;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.misc.TransactionManager;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

import java.sql.SQLException;

/**
 * Created by lenovo on 2016/7/16.
 */
public class ORMliteHelper extends OrmLiteSqliteOpenHelper {

    private static final String DATABASE_NAME = "CatGame.db";

    private static final String TAG = "TAG";
    public ORMliteHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
    }


    @Override
    public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
        try {
            int state = TableUtils.createTable(connectionSource, UserBean.class);
            int state2 = TableUtils.createTable(connectionSource, HotTag.class);
          //  Log.i(TAG,"oncreate:"+state);
            Log.i("table","oncreate2:"+state2);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
        try {
           int state = TableUtils.dropTable(connectionSource, UserBean.class,true);
            int state2 = TableUtils.dropTable(connectionSource, HotTag.class,true);
            onCreate(database,connectionSource);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
